/**
 * MLiveActivity.java
 * 版权所有(C) 2014
 * 创建者:cuiran 2014-10-30 下午1:37:15
 */
package com.ghyf.mplay;

import org.videolan.vlc.audio.AudioServiceController;

import android.os.Bundle;
import android.view.ViewGroup;
import android.view.WindowManager;
import android.view.ViewGroup.LayoutParams;
import android.widget.FrameLayout;

import com.ghyf.mplay.bean.GlobalParamInfo;
import com.ghyf.mplay.bean.VideoSurfaceInfo;
import com.ghyf.mplay.datatype.POS;
import com.ghyf.mplay.util.LogUtil;

/**
 * 直播Activity 弹出式界面
 * @author cuiran
 * @version 1.0.0
 */
public class MLiveActivity extends BaseActivity {

	private static final String TAG="MLiveActivity";
	private ViewGroup viewGroup;
	private VideoSurfaceInfo surfaceInfo=null;
	public static MLiveActivity instance=null;
	
	@Override
	 public void onCreate(Bundle savedInstanceState) {
		 super.onCreate(savedInstanceState);
		 //650,95,1250,800
		 	surfaceInfo=VideoSurfaceInfo.getInstance();
		 	POS pos= surfaceInfo.getModule_Pos();
		 	WindowManager.LayoutParams layoutParams0 = getWindow().getAttributes(); 
			String out=GlobalParamInfo.getInstance().getOut_resolution();
			String [] dm=out.split("x");
			if(dm==null||dm.length<=0)return;
			int screenWidth = Integer.parseInt(dm[0]); // 屏幕宽（像素，如：480px）
			int screenHeight = Integer.parseInt(dm[1]); // 屏幕高（像素，如：800p）
			
			 layoutParams0.x=0-screenWidth+pos.getLeft();
			 layoutParams0.y=0-screenHeight+pos.getTop();
			 layoutParams0.width=pos.getWidth();
			 layoutParams0.height=pos.getHeight();
			 
			 instance=this;
			 viewGroup = new FrameLayout(getApplicationContext()); // 创建控件容器，显示布局
			 LayoutParams layoutParams1=new LayoutParams(pos.getWidth(), pos.getHeight());
			 viewGroup.setLayoutParams(layoutParams1); // 设置容器的宽高
			 setContentView(viewGroup);
	
			 viewGroup.addView(surfaceInfo.getView(this));
			 surfaceInfo.startPlay();
		 
	
		 
		 
	 }
	
	
	@Override
	protected void onPause() {
		super.onPause();
		AudioServiceController.getInstance().unbindAudioService(this);
		LogUtil.i(TAG, "onPause");
		surfaceInfo.onPause();
	}


	@Override
	protected void onResume() {
		super.onResume();
		AudioServiceController.getInstance().bindAudioService(this);
		LogUtil.i(TAG, "onResume");
		
	}
	
	@Override
	protected void onStop() {
		super.onStop();
		LogUtil.i(TAG, "onStop");
		surfaceInfo.onStop();
		
	}

	@Override
	protected void onDestroy() {
		super.onDestroy();
		LogUtil.i(TAG, "onDestroy");
		surfaceInfo.onDestroy();
		instance=null;
	 }

	
	
}
